package com.yiyuan.app.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guaike.core.mybatis.plugins.BaseDAO;
import com.yiyuan.app.entity.po.UAppUserEquityPO;
import com.yiyuan.app.mapper.UAppUserEquityExtMapper;
import com.yiyuan.app.mapper.UAppUserEquityMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

@Repository
@AllArgsConstructor
public class UAppUserEquityDAO extends BaseDAO<UAppUserEquityMapper, UAppUserEquityPO> {

    private final UAppUserEquityExtMapper uAppUserEquityExtMapper;

    public int addPinecone(Long userId, Integer pinecone) {
        return uAppUserEquityExtMapper.addPinecone(userId, pinecone);
    }

    public int updatePineNut(Long userId, Integer pineNut) {
        return uAppUserEquityExtMapper.updatePineNut(userId, pineNut);
    }

    public List<UAppUserEquityPO> findWeekPineconeRank() {
        LambdaQueryWrapper<UAppUserEquityPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(UAppUserEquityPO::getPinecone);
        queryWrapper.last("limit 0,10");
        return getBaseMapper().selectList(queryWrapper);
    }

    public UAppUserEquityPO findByUserIdLock(Long userId) {
        return uAppUserEquityExtMapper.findByUserIdLock(userId);
    }

    public int addManageMoney(Long userId, BigDecimal manageMoney) {
        return uAppUserEquityExtMapper.addManageMoney(userId, manageMoney);
    }
}
